package logic.SysPerson

import cn.ibizlab.util.domain.EntityBase
import cn.ibizlab.util.helper.RuleUtils
import cn.ibizlab.util.security.AuthenticationUser
import cn.ibizlab.util.security.SpringContextHolder
import cn.ibizlab.core.ad.domain.SysPerson
import cn.ibizlab.core.ad.service.SysPersonService
import com.alibaba.fastjson.JSONObject
import org.springframework.util.ObjectUtils

/**
 *  新建前默认处理
 */
class BeforeNew {

    //当前用户
    def curuser = AuthenticationUser.getAuthenticationUser()
    //传入变量
    def _default
    //返回参数
    def _return

    def execute(arg) {
        println 'running....'
        _default = arg
        _return = arg
        begin()
        println 'running end....'
        return _return
    }

    //开始
    def begin() {
    
        //id为空，dc为空
        if(((RuleUtils.test(_default.get('id'), 'ISNULL', 'null')) && (RuleUtils.test(_default.get('dc'), 'ISNULL', 'null')))) {
            prepareparam1()
        }
        //连接名称
        if(true) {
            prepareparam2()
        }
    }

    //用uid为id
    def prepareparam1() {
        _default.set("id", _default.get("uid"))

        if(true) {
            prepareparam2()
        }
    }

    //准备参数
    def prepareparam2() {
        _default.set("user_password", "123456")

        if(true) {
            rawsqlcall1()
        }
    }

    //直接SQL调用
    def rawsqlcall1() {
        Map param =new HashMap();
        param.put("param0",_default.get("id"));
        String strSql="""
    delete from sys_person where enabled=0 and id = #{et.param0}
        """
        SpringContextHolder.getBean(SysPersonService.class).select(strSql,param)

        if(true) {
            end1()
        }
    }

    //结束
    def end1() {
        _return = _default

    }

}
